package com.cross.mutil;

import com.cross.core.AbstractWriter;
import com.cross.core.Header;
import com.cross.core.Writer;
import com.cross.exception.CrossException;
/**
 * 复合写入器:将多个写入器合并为一个写入器，
 * 能依次将数据写入到各个分写入器中
 * @author wu
 *
 */
public class SimpleMutilWriter extends AbstractWriter {

	private Writer[] writers;
	
	public SimpleMutilWriter(final Header header, final Writer... writers) throws CrossException {
		if(writers==null){
			throw new CrossException("空指针异常");
		}
		super.setHeader(header);
		this.writers = writers;
		for(Writer w : writers){
			w.setHeader(header.clone());
		}
	}
	@Override
	protected void writeRow() {
		for(Writer w : writers){
			w.write(currentRow);
		}
	}

	@Override
	public void close() {
		for(Writer w : writers){
			w.close();
		}
	}

}
